import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class UploadService extends BaseService<any> {
  private readonly logger = new Logger(UploadService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * image
   * 对应 PHP: UploadService_admin::image()
   * 逻辑类型: undefined - undefined
   */
  async image(file: number, cate_id: number, is_attachment: number) {
    // 基于PHP真实逻辑: image
    // PHP原文: $dir = $this->root_path . '/' . 'image' . '/' . $this->site_id . '/' . date('Ym') . '/' . date('d');         $core_upload_service = new CoreUploadServ...
const dir = this.root_path  + '/'  + 'image'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(is_attachment];
        //如果没有选择相册分组的话,就选择第一个相册分组
        return core_upload_service.image(file, this.site_id, dir, cate_id);
    }

    /**
     * 附件库上传视频
     * @param file
     * @param int cate_id
     * @return */
    async video(file, int cate_id = 0)
    {
        const dir = this.root_path  + '/'  + 'video'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(true];
        return core_upload_service.video(file, this.site_id, dir, cate_id);
    }

    /**
     * 附件库上传音频
     * @param file
     * @param int cate_id
     * @return */
    async audio(file, int cate_id = 0)
    {
        const dir = this.root_path  + '/'  + 'audio'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(true];
        return core_upload_service.audio(file, this.site_id, dir, cate_id);
    }

    /**
     * 文件上传
     * @param file
     * @param string type
     * @return * @throws BusinessException
     */
    async document(file, string type)
    {
        if (!in_[type, FileDict.getSceneType()))
            throw new UploadFileBusinessException('UPLOAD_TYPE_ERROR');
        const dir = this.root_path  + '/document/' . type  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = this.coreUploadService;
        return core_upload_service.document(file, this.site_id, type, dir, StorageDict.LOCAL);
    }
}
  }

  /**
   * video
   * 对应 PHP: UploadService_admin::video()
   * 逻辑类型: undefined - undefined
   */
  async video(file: number, cate_id: number) {
    // 基于PHP真实逻辑: video
    // PHP原文: $dir = $this->root_path . '/' . 'video' . '/' . $this->site_id . '/' . date('Ym') . '/' . date('d');         $core_upload_service = new CoreUploadServ...
const dir = this.root_path  + '/'  + 'video'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(true];
        return core_upload_service.video(file, this.site_id, dir, cate_id);
    }

    /**
     * 附件库上传音频
     * @param file
     * @param int cate_id
     * @return */
    async audio(file, int cate_id = 0)
    {
        const dir = this.root_path  + '/'  + 'audio'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(true];
        return core_upload_service.audio(file, this.site_id, dir, cate_id);
    }

    /**
     * 文件上传
     * @param file
     * @param string type
     * @return * @throws BusinessException
     */
    async document(file, string type)
    {
        if (!in_[type, FileDict.getSceneType()))
            throw new UploadFileBusinessException('UPLOAD_TYPE_ERROR');
        const dir = this.root_path  + '/document/' . type  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = this.coreUploadService;
        return core_upload_service.document(file, this.site_id, type, dir, StorageDict.LOCAL);
    }
}
  }

  /**
   * audio
   * 对应 PHP: UploadService_admin::audio()
   * 逻辑类型: undefined - undefined
   */
  async audio(file: number, cate_id: number) {
    // 基于PHP真实逻辑: audio
    // PHP原文: $dir = $this->root_path . '/' . 'audio' . '/' . $this->site_id . '/' . date('Ym') . '/' . date('d');         $core_upload_service = new CoreUploadServ...
const dir = this.root_path  + '/'  + 'audio'  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = new CoreUploadService(true];
        return core_upload_service.audio(file, this.site_id, dir, cate_id);
    }

    /**
     * 文件上传
     * @param file
     * @param string type
     * @return * @throws BusinessException
     */
    async document(file, string type)
    {
        if (!in_[type, FileDict.getSceneType()))
            throw new UploadFileBusinessException('UPLOAD_TYPE_ERROR');
        const dir = this.root_path  + '/document/' . type  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = this.coreUploadService;
        return core_upload_service.document(file, this.site_id, type, dir, StorageDict.LOCAL);
    }
}
  }

  /**
   * document
   * 对应 PHP: UploadService_admin::document()
   * 逻辑类型: undefined - undefined
   */
  async document(file: string, type: string) {
    // 基于PHP真实逻辑: document
    // PHP原文: if (!in_array($type, FileDict::getSceneType()))             throw new UploadFileException('UPLOAD_TYPE_ERROR');         $dir = $this->root_path . '/do...
if (!in_[type, FileDict.getSceneType()))
            throw new UploadFileBusinessException('UPLOAD_TYPE_ERROR');
        const dir = this.root_path  + '/document/' . type  + '/' . this.site_id  + '/' . date('Ym')  + '/' . date('d'];
        const core_upload_service = this.coreUploadService;
        return core_upload_service.document(file, this.site_id, type, dir, StorageDict.LOCAL);
    }
}
  }
}
